package cn.breeze.basic.service.impl;

import cn.breeze.basic.mapper.BaseMapper;
import cn.breeze.basic.query.BaseQuery;
import cn.breeze.basic.service.IBaseService;
import cn.breeze.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {


    @Autowired
    private BaseMapper<T> baseMapper;


    /**
     * @Title: loadAll
     * @Description: TODO
     * @Author: Mr.D
     * @Version: 1.0
     * @Date:  2022/6/21 18:39
     * @Parameters: []
     * @Return java.util.List<cn.breeze.org.domain.T>
     */
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    /**
     * @Title: loadById
     * @Description: TODO
     * @Author: Mr.D
     * @Version: 1.0
     * @Date:  2022/6/21 18:47  
     * @Parameters: [id]
     * @Return cn.breeze.org.domain.T
     */
    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    /**
     * @Title: remove
     * @Description: TODO
     * @Author: Mr.D
     * @Version: 1.0
     * @Date:  2022/6/21 18:46  
     * @Parameters: [id]
     * @Return
     */
    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    /**
     * @Title: save
     * @Description: TODO
     * @Author: Mr.She
     * @Version: 1.0
     * @Date:  2022/6/21 18:39
     * @Parameters: [t]
     * @Return void
     */
    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    /**
     * @Title: update
     * @Description: TODO
     * @Author: Mr.She
     * @Version: 1.0
     * @Date:  2022/6/21 18:38  
     * @Parameters: [t]
     * @Return void
     */
    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    /**
     * @Title: queryData
     * @Description: TODO
     * @Author: Mr.She
     * @Version: 1.0
     * @Date:  2022/6/21 18:36  
     * @Parameters: [baseQuery]
     * @Return cn.breeze.basic.utils.PageList<cn.breeze.org.domain.T>
     */
    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {

        // 1.查询分页总条数
        Integer total = baseMapper.queryCount(baseQuery);
        // 2.查询当前页数据
        List<T> rows = baseMapper.queryData(baseQuery);

        return new PageList<T>(total, rows);
    }

    @Override
    public void patchRemove(Long[] ids) {
        baseMapper.patchRemove(ids);
    }
}
